<template>
  <div class="resume">
    <van-nav-bar title="简历" left-text="" fixed placeholder left-arrow @click-left="$router.back()">
    </van-nav-bar>
    <div class="content">
      <van-tabs v-model="activeName" @click="tabs">
        <van-tab title="已投简历" name="1">
          <div class="yitoujianl">
            <div class="contents-center">
              <div class="contents-center-item" v-for="(item,index) in resumeArr" :key="index">
                <div class="imgs">
                  <img :src="item.cover" alt="">
                </div>
                <div class="contents-c-item">
                  <div class="title">
                    <h3>{{item.title}}</h3>
                  </div>
                  <div class="contents">
                    <p>{{item.describes}}</p>
                  </div>
                  <div class="contents-text">
                    <div class="contents-text-item">
                      <img src="../../assets/images/invite/fenxiang.png" alt="">
                      <p>转发:{{item.share || 0}}次</p>
                    </div>
                    &nbsp;&nbsp;
                    <div class="contents-text-item" @click.stop="goDetail(item)">
                      <img src="../../assets/images/invite/yuedu.png" alt="">
                      <p>阅读:{{item.score || 0}}次</p>
                    </div>
                    &nbsp;&nbsp;
                    <div class="contents-text-item">
                      <span>{{item.gmtCreate.substring(0,11)}}</span>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </van-tab>
        <van-tab title="我的简历" name="2">
          <div class="scjl">
            <div class="xxresume">
              <h3 style="padding:12px" v-if="xxmyresumeArr.length==0">上传详细在线简历</h3>
              <h3 style="padding:12px" v-else>详细在线简历</h3>
              <h4 style="color:red;padding-left:12px;font-size:15px" v-if="xxmyresumeArr.length==0">上传详细简历可提高80%求职成功率</h4>
              <div class="contents-formtitle" v-for="(item,index) in xxmyresumeArr" :key="index">
                <div class="contents-left">
                  <img src="../../assets/images/resume/jianli.png" alt="">
                </div>
                <div class="contents-center">
                  <span>{{item.name}}</span>
                  <p>{{item.gmtCreate.substring(0,11)}}上传</p>
                </div>
                <div class="contents-right">
                  <div class="content-right1" style="margin-right:20px;" @click="$router.push({path:'/detailedonlineresumes',query:{id:xxmyresumeArr[0].id}})">
                    <img style="width:15px;height:15px;" src="../../assets/images/invite/cj.png" alt="">
                  </div>
                  <div class="contents-right2" @click.stop="deleteRecruit(item.id)">
                    <van-icon name="delete-o" style="color:red;display:block;font-size:20px;margin-top:30px" />
                  </div>
                </div>
              </div>
              <div class="contents-formMsg" v-if="xxmyresumeArr.length==0" @click="$router.push({path:'/detailedonlineresumes'})">
                <span>
                  <img style="width:13px;height:13px;margin-right:4px" src="../../assets/images/invite/add.png" alt="">
                  <span style="margin-top:-5px">创建详细在线简历</span>
                </span>
              </div>
            </div>

            <div class="jyresume">
              <h3 style="padding:12px" v-if="jymyresumeArr.length==0">上传简易在线简历</h3>
              <h3 style="padding:12px" v-else>简易在线简历</h3>
              <div class="contents-formtitle" v-for="(item,index) in jymyresumeArr" :key="index">
                <div class="contents-left">
                  <img src="../../assets/images/resume/jianli.png" alt="">
                </div>
                <div class="contents-center">
                  <span>{{item.name}}</span>
                  <p>{{item.gmtCreate.substring(0,11)}}上传</p>
                </div>
                <div class="contents-right">
                  <div class="content-right1" style="margin-right:20px;" @click="$router.push({path:'/briefonlineresumes',query:{id:jymyresumeArr[0].id}})">
                    <img style="width:15px;height:15px;" src="../../assets/images/invite/cj.png" alt="">
                  </div>
                  <div class="contents-right2" @click.stop="deleteRecruit(item.id)">
                    <van-icon name="delete-o" style="color:red;display:block;font-size:20px;margin-top:30px" />
                  </div>
                </div>
              </div>
              <div class="contents-formMsg" v-if="jymyresumeArr.length==0" @click="$router.push({path:'/briefonlineresumes'})">
                <span>
                  <img style="width:13px;height:13px;margin-right:4px" src="../../assets/images/invite/add.png" alt="">
                  <span style="margin-top:-5px">创建简易在线简历</span>
                </span>
              </div>
            </div>

            <div class="scresume">
              <div class="titless">
                <h3 style="padding:12px">上传简历</h3>
                <span>(仅支持PDF上传，大小在2M)</span>
              </div>
              <div class="contents-formtitle" v-for="(item,index) in myresumeArr" :key="index">
                <div class="contents-left">
                  <img src="../../assets/images/invite/pdf.png" alt="">
                </div>
                <div class="contents-center">
                  <span>{{item.fileName}}</span>
                  <p>{{item.gmtCreate.substring(0,11)}}上传</p>
                </div>
                <div class="contents-right" @click.stop="deleteRecruit(item.id)">
                  <van-icon name="delete-o" style="color:red;display:block;font-size:20px;margin-top:30px" />
                </div>
              </div>
              <label for="upload" v-if="myresumeArr.length==0">
                <div class="contents-formMsg">
                  <span>
                    <img style="width:13px;height:13px;margin-right:4px" src="../../assets/images/invite/add.png" alt="">
                    <span style="margin-top:-5px">上传简历</span>
                  </span>
                  <input id="upload" style="display:none" type="file" accept="application/pdf" @change="uplodadgongzonghao" class="abc">
                </div>
              </label>
            </div>
            <div class="contentsss">
              <div class="contents-title">
                <div class="content-left">
                  <img src="../../assets/images/invite/shu.png" alt="">
                  <span>职位列表</span>
                </div>
              </div>
              <div class="contents-center" v-if="recruitmentArr.length">
                  <van-list
                    v-model="loading"
                    :finished="finished"
                    finished-text="没有更多了"
                    @load="onLoad"
                  >
                <van-cell-group v-for="(item,index) in recruitmentArr" :key="index" @click="$router.push({path:'/recruitmentdetails',query:{id:item.id,type:2}})">
                  <div class="contents-center-item">
                    <div class="imgs">
                      <img src="../../assets/images/task/getMoney.png" alt="" class="money" v-show="item.type == 9" />
                      <img :src="item.cover" alt="">
                    </div>
                    <div class="contents-b-item">
                      <div class="left">
                        <div class="title">
                          <h3>{{item.title}}</h3>
                        </div>
                        <div class="contentss">
                          <p>{{item.describes}}</p>
                        </div>
                        <div class="contents-text">
                          <div class="contents-text-item">
                            <p>转发：{{item.share || 0}}次</p>
                          </div>
                          <div class="contents-text-item">
                            <p>阅读：{{item.score || 0}}次</p>
                          </div>
                          <div class="contents-text-item">
                            <p>{{item.gmtCreate.substring(0,11)}}</p>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </van-cell-group>
                </van-list>
              </div>
              <van-empty description="当前暂无招聘内容~" class="custom-image" :image="require('../../assets/dafault/noinvite.png')" v-else>
                <van-button round type="danger" class="bottom-button" @click="goAdd">去新建招聘</van-button>
              </van-empty>
            </div>
          </div>
        </van-tab>
      </van-tabs>
    </div>
  </div>
</template>
<script>
import { Dialog } from 'vant';
export default {
  data () {
    return {
      activeName: "2",
      checked: "1",
      resumeArr: [],
      myresumeArr: [],
      xxmyresumeArr: [],//详细在线简历列表
      jymyresumeArr: [],//详细在线简历列表
      recruitmentArr: [],
      loading: false, //加载状态
      finished: false, //完成
      page: 1, //页数
      limit: 8, //条数
      totalPage: "", //总页数
      isPower:3,
      info: "",
      wxUserInfo:{}
    }
  },
  mounted () {
    this.wxUserInfo = JSON.parse(sessionStorage.getItem("userWxData"));
    this.tabs(2)
    this.isCustomer();
  },
  methods: {
      //触底下一页
    onLoad() {
      if (this.page >= this.totalPage) {
        this.finished = true;
        return;
      }
      this.page++;

      this.getRecruitss();
      // 加载状态结束
      this.loading = false;
    },
    //点击跳转详情
    goDetail(item) {
        if (this.isPower == 3) return this.$toast("权限不足！");
        let obj = {
            cover:item.cover,
            title:item.title,
            description:item.describes,
            share:item.share,
            score:item.score,
            gmtCreate:item.gmtCreate,
        };
        sessionStorage.setItem("taskDetail", JSON.stringify(obj));
        this.$router.push(`/taskDetails?id=${item.id}&title=招聘`);
    },
    tabs(name){
      if(name==2){
        this.myResume();
        this.getRecruitss()
      }else{
        this.recruitsubmitResume();
      }
    },
    //判断是否有权限创建
    async isCustomer () {
      let account = sessionStorage.getItem("agentId");
      let res = await this.$api.isCustomer({
        openId: this.wxUserInfo.openid,
        account,
        id: this.$store.state.userInfo.id,
        phone: this.$store.state.userInfo.phone,
      });
      this.isPower = res.data;
      this.info = res.info;
    },
    //去创建
    goAdd () {
      if (this.isPower == 3 && this.info != " ") {
        return this.$router.push("/mineInstructions");
      } else if (this.isPower == 3 && this.info == " ") {
        return this.$toast("您的权限不足！");
      }
      if (this.isPower) {
        this.$router.push({ path: "/addRecruitment" });
      }
    },
    // 获取招聘-立即发布
    async getRecruitss () {
      let obj = {
        account: sessionStorage.getItem("agentId"),
        type: 9,
        status: 2,
        page:this.page,
        limit:this.limit
      }
      let res = await this.$api.getRecruit(obj);
         //判断是否是第一页
      if (this.page == 1) {
        this.recruitmentArr = res.data.list || [];
      } else {
        this.recruitmentArr.push(...res.data.list);
      }
      this.totalPage = res.data.totalPage;
    },
    // 简历删除
    deleteRecruit (id) {
      Dialog.confirm({
        title: '删除提示',
        message: '确认删除此条简历信息吗？',
      }).then(() => {
        this.$api.deleteRecruit({ id: id }).then(res => {
          if (res.code == 0) {
            this.$toast("删除成功")
            this.$router.go(0);
            sessionStorage.setItem("resumeId", "")
          } else {
            this.$toast("删除失败")
          }
        })
      })
    },
    //   简历上传
    uplodadgongzonghao (e) {
      const file = e.target.files[0] || e.dataTransfer.files[0]
      if (file.size / 1024 < 2048) {
        this.afterReads(file)
      } else {
        return this.$toast("请选择小于2M的简历上传")
      }
    },
    //上传pdf
    afterReads (files) {
      let _this = this;
      _this.$publicObj.getLoading();
      _this.$publicObj.uploadFile(
        files,
        function (res) {
          let obj = {}
          if (sessionStorage.getItem("resumeId") == "" || sessionStorage.getItem("resumeId") == undefined) {
            obj.type = 3;
            obj.fileName = files.name;
            obj.resume = res;
            obj.customerId = sessionStorage.getItem("agentIds")
          } else {
            obj.id = sessionStorage.getItem("resumeId");
            obj.type = 3;
            obj.fileName = files.name;
            obj.resume = res;
            obj.customerId = sessionStorage.getItem("agentIds")
          }
          _this.$api.addRecruitTalent(obj).then((res) => {
            if (res.code == 0) {
              _this.$toast("上传成功");
              _this.$router.go(0)
            } else {
              return;
            }
          })
          _this.$publicObj.closeLoading();
        },
        "/sys/oss/uploadFile"
      );
    },
    recruitsubmitResume () {
      this.$api.recruitsubmitResume({ id: sessionStorage.getItem('agentIds') }).then(res => {
        this.resumeArr = res.data
      })
    },
    myResume () {
      this.$api.myResume({ id: sessionStorage.getItem('agentIds') }).then(res => {
        if (res.data) {
          res.data.forEach(item => {
            sessionStorage.setItem("resumeId", item.id)
            if (item.type == 1) {
              let obj = {
                id: item.id,
                name: item.name,
                gmtCreate: item.gmtCreate
              }
              this.xxmyresumeArr.push(obj)
            } else if (item.type == 2) {
              let obj = {
                id: item.id,
                name: item.name,
                gmtCreate: item.gmtCreate
              }
              this.jymyresumeArr.push(obj)
            } else if (item.type == 3) {
              let obj = {
                id: item.id,
                fileName: item.fileName,
                gmtCreate: item.gmtCreate
              }
              this.myresumeArr.push(obj)
            }
          })
        } else {
          return;
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
.bottom-button {
  width: 130px;
  height: 34px;
  background-color: #477fe6;
  border-radius: 17px;
  border: none;
  font-size: 13px;
  color: #ffffff;
}
.contentsss {
  padding-bottom: 50px;
  .contents-title {
    display: flex;
    justify-content: space-between;
    .content-left {
      display: flex;
      padding: 8px 20px;
      img {
        width: 4px;
        height: 20px;
      }
      span {
        margin: 0.5px 10px;
        font-size: 14px;
        color: #3b447a;
      }
    }
    .content-right {
      display: flex;
      span {
        display: block;
        margin-top: 11px;
        font-size: 14px;
        color: #3b447a;
      }
      .van-icon {
        margin-top: 13px;
        margin-right: 12px;
      }
    }
  }
  .contents-center {
    .contents-center-item {
      display: flex;
      padding: 12px;
      border-bottom: 1px solid ghostwhite;
      .imgs {
        flex: 1.5;
        width: 90px;
        height: 90px;
        margin-right: 15px;
        position: relative;
        img {
          width: 100%;
          height: 100%;
          border-radius: 5px;
        }
        .money {
          width: 35px;
          height: 35px;
          position: absolute;
          right: 0;
          top: 0;
          border-radius: none;
        }
      }
      .contents-b-item {
        flex: 4;
        margin-top: 10px;
        .left {
          .title {
            h3 {
              display: block;
              font-size: 14px;
              color: #333333;
            }
          }
          .contentss {
            margin-top: 2px;
            p {
              font-size: 11px;
              color: #999999;
              height: 36px;
              display: -webkit-box;
              overflow: hidden;
              -webkit-box-orient: vertical;
              text-overflow: ellipsis;
              -webkit-line-clamp: 2;
            }
          }
          .bottom {
            display: flex;
            margin-top: 8px;
            justify-content: space-between;
            .lefts {
              display: flex;
              img {
                width: 40px;
                height: 20px;
              }
              .img2 {
                margin-left: 12px;
              }
            }
            .rights {
              margin-right: 12px;
            }
          }
          .contents-text {
            display: flex;
            justify-content: space-between;
            font-size: 11px;
            color: #999;
            .contents-text-item {
              display: flex;
              flex: 2;
              justify-content: space-between;
              margin-top: 10px;
              img {
                width: 12px;
                height: 12px;
                margin-top: 2px;
              }
              p {
                margin-left: 5px;
              }
            }
          }
        }
      }
    }
  }
}
.btn {
  width: 80%;
  height: 41px;
  background: #477fe6;
  border-radius: 21px;
  text-align: center;
  margin: 40px auto;
  color: #fff;
  line-height: 41px;
}
.content {
  height: calc(100vh - 96px) !important;
  overflow-y: scroll;
  .yitoujianl {
    padding-bottom: 10px;
  }
}

.titless {
  display: flex;
  span {
    margin-top: 14px;
    font-size: 12px;
  }
}
.contents-formMsg {
  width: 90%;
  height: 35px;
  text-align: center;
  border: 1px dashed #477fe6;
  border-radius: 8px;
  margin: 20px auto;
  line-height: 35px;
}

.contents-formtitle {
  display: flex;
  width: 100vw;
  padding-left: 20px;
  .contents-left {
    flex: 1;
    img {
      width: 40px;
      height: 50px;
      display: block;
      margin: 15px auto;
    }
  }
  .contents-center {
    flex: 3;
    span {
      display: block;
      margin-top: 20px;
    }
    p {
      color: #999;
      margin-top: 12px;
      font-size: 12px;
    }
  }
  .contents-right {
    flex: 2;
    color: red;
    line-height: 75px;
    display: flex;
  }
}
.contents-center-item {
  display: flex;
  margin: 6px 20px;
  line-height: 20px;
  .imgs {
    width: 40%;
    height: 100px;
    margin: 10px 0;
    img {
      width: 80px;
      height: 80px;
    }
  }
  .contents-c-item {
    width: 100%;
    height: 100px;
    margin: 8px 20px;
    .title {
      h3 {
        font-size: 18px;
      }
    }
    .contents {
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      p {
        display: block;
        font-size: 14px;
        height: 36px;
        color: #999;
        display: -webkit-box;
        overflow: hidden;
        -webkit-box-orient: vertical;
        text-overflow: ellipsis;
        -webkit-line-clamp: 2;
      }
    }
    .contents-text {
      display: flex;
      font-size: 11px;
      justify-content: space-between;
      color: #999;
      .contents-text-item {
        display: flex;
        margin-top: 10px;
        img {
          width: 12px;
          height: 12px;
          margin-top: 2px;
        }
        p {
          margin-left: 5px;
          display: block;
        }
      }
    }
  }
}
</style>